package com.zerocarbon.framework.web.handler;

import com.zerocarbon.framework.common.dto.BaseDTO;
import com.zerocarbon.framework.common.result.vo.AuthTokenVO;
import com.zerocarbon.framework.core.context.UserContextHandler;
import com.zerocarbon.framework.web.extension.ValidateResult;

/**
 * 验证类
 * @author wyf  2020年6月17日
 */
public interface IValidRestHandler {
	
	/**
	 * 验证签名
	 * @param param
	 * @param appSecret
	 * @return
	 * @throws Exception
	 */
	<T> ValidateResult<T> validateSgin(BaseDTO param, String appSecret) throws Exception;
	
	/**
	 * 验证用户认证
	 * @param authorization
	 * @return
	 * @throws Exception
	 */
	<T> ValidateResult<T> validateAuth(String authorization) throws Exception;
	
	/**
	 * 根据APPkey获取AppSecret
	 * @param appKey
	 * @return
	 */
	default String getAppSecret(String appKey) {
		return null;
	}
	
	/**
	 * 更新用户信息上下文
	 * @param authTokenVO
	 */
	default void updateUserContext(AuthTokenVO authTokenVO) {
		UserContextHandler.setTenantId(authTokenVO.getTenantId());
		UserContextHandler.setAccountId(authTokenVO.getAccountId());
		UserContextHandler.setUserId(authTokenVO.getUserId());
		UserContextHandler.setUserIdentity(authTokenVO.getUserIdentity());
		UserContextHandler.setUserMobile(authTokenVO.getUserMobile());
		UserContextHandler.setUserName(authTokenVO.getUserName());
		UserContextHandler.setCompanyId(authTokenVO.getCompanyId());
		UserContextHandler.setCompanyName(authTokenVO.getCompanyName());
    }
}
